// pages/app/majorInfo/majorInfo.js
const app = getApp();
var host = app.globalData.host;
var utils = app.globalData.utils;
var self = null;

Page({
  data: {
    themeColor: '',
    defaultColor: '',
    borderColor: '',
    info: {},
    // 首页模块进入
    majorId: '',
    // 录取标准模块进入
    schoolMajorId: '',
    schoolId: '',
    majorRankScoreId: ''
  },
  onLoad: function (options) {
    self = this;
    self.getStyle();
    if (options.majorId) {
      self.setData({
        majorId: options.majorId
      })
    }
    if (options.schoolMajorId) {
      self.setData({
        schoolMajorId: options.schoolMajorId,
        schoolId: options.schoolId,
        majorRankScoreId: options.majorRankScoreId
      })
    }
    self.init();
  },
  init() {
    var url = host + '/lx/mini/school/majorInfo';
    var params = {
      majorId: self.data.majorId,
      schoolMajorId: self.data.schoolMajorId,
      schoolId: self.data.schoolId,
      majorRankScoreId: self.data.majorRankScoreId
    };
    var success = function (res) {
      var info = res.info;
      // 拉夫堡，威斯敏斯特，伍斯特，曼彻斯特，布里斯托
      if (info.originRequirement && (info.schoolId == 1 || info.schoolId == 2 || info.schoolId == 3 || info.schoolId == 4 || info.schoolId == 5)) {
        info.requirement = info.originRequirement;
      }
      self.setData({
        info: res.info
      })
    }
    var fail = function (res) {
      wx.navigateBack({
        delta: 1
      })
      wx.showToast({
        title: String(res.msg),
        icon: 'none'
      })
    };
    var complete = function () { };
    utils.request(url, params, success, fail, complete);
  },
  getStyle() {
    self.setData({
      themeColor: app.globalData.themeColor,
      defaultColor: app.globalData.defaultColor,
      borderColor: app.globalData.borderColor
    })
  }
})